#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

#
# Run a simple backup of the Bacula build directory using the compressed option
#   then restore it.
#

TestName="restore-by-file-test"
JobName=restorebyfile
. scripts/functions

scripts/cleanup
scripts/copy-test-confs
echo "${cwd}/tmp/build" >${cwd}/tmp/file-list
mkdir -p ${cwd}/tmp/build
cp -p ${cwd}/build/src/dird/*.c ${cwd}/tmp/build
cd ${cwd}/tmp/build
ls >../1
cd ..
sed s%\^%${cwd}/tmp/build/% 1 | sort | uniq >restore-list
echo $tmp/build/fr.po >> restore-list
rm -f 1
cd ${cwd}

change_jobname CompressedTest $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@output /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
@exec "cp $cwd/build/po/fr.po $tmp/build"
run job=$JobName yes
wait
messages
@# 
@# now run 10 restores
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
restore where=${cwd}/tmp/bacula-restores storage=File
7
<${cwd}/tmp/restore-list

yes
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File
stop_bacula

check_two_logs
check_restore_tmp_build_diff
end_test
